#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
    @Author 黄海峰
    @Date 2021/4/14 18:43
    @Version 1.0.0
"""

import threading


def A():
    print('1')
    print('2')
    print('3')


def B():
    print('x')
    print('y')
    print('z')


t1 = threading.Thread(target=A)
t2 = threading.Thread(target=B)
t1.start()
t2.start()
t1.join()
t2.join()
print('===========')


def consumer():
    r = ''
    while True:
        n = yield r
        if not n:
            return
        print('[CONSUMER] Consuming %s...' % n)
        r = '200 OK'


def produce(c):
    c.send(None)
    n = 0
    while n < 5:
        n = n + 1
        print('[PRODUCER] Producing %s...' % n)
        r = c.send(n)
        print('[PRODUCER] Consumer return: %s' % r)
    c.close()


c = consumer()
produce(c)
